#!/bin/sh

###################################################################
# File Name: winrar_download.sh
# Author: liaoxuecheng
# mail: liaoxuecheng@hotmail.com
# Created Time: 2025年01月20日 星期一 11时37分31秒
###################################################################

COMMON="https://www.win-rar.com/fileadmin/winrar-versions/sc/"
#platform wrr or rrlb
platform='rrlb'
#bit x32 x64
bit='x64'
vtime='202405'
version='701'

main()
{
   for((i=31;i>=10;i--))
    do
        url="$COMMON"sc$vtime$i/$platform/winrar-$bit-${version}sc.exe
        if wget --spider --no-check-certificate -q $url
        then
            echo $url
            exit 0
        fi
    done
}

param_handle()
{
    while true
    do
        case "$1" in
            -h)
                echo 'Usage: $0 [ -p {rrlb/wrr}] [ -b {32/64}] [ -t time ] [ -v version ]'
                exit 0
                ;;
            -p)
                platform=$2
                shift 2;;
            -b)
                bit=$2
                shift 2;;
            -t)
                vtime=$2
                shift 2;;
            -v)
                version=$2
                shift 2;;
            --)
                shift
                break;;
            *)
                shift;;
        esac
    done
}

TEMP=`getopt -o 'p:b:t:v:h' -- "$@"`
[ $? != 0 ] && echo "Terminating....." >&2 && exit 1
eval set -- "$TEMP"
param_handle $@
main $@

#最新版本:  wrr  --- rrlb  都可以

#7.01
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20240528/wrr/winrar-x32-701sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20240528/wrr/winrar-x64-701sc.exe
#
#7.00
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20240306/rrlb/winrar-x32-700sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20240306/rrlb/winrar-x64-700sc.exe
#
#WinRAR 6.24 官方暗链接2023-10-13 数字签名日期，下载链接不变。
#https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20231013/wrr/winrar-x64-624sc.exe
#https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20231013/wrr/winrar-x32-624sc.exe
#或
#https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20231013/rrlb/winrar-x64-624sc.exe
#https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20231013/rrlb/winrar-x32-624sc.exe
#
#WinRAR 6.23 官方暗链接 2023-09-08 数字签名日期，下载链接不变。
#https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230808/wrr/winrar-x32-623sc.exe
#https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230808/wrr/winrar-x64-623sc.exe
#6.22
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230607/wrr/winrar-x32-622sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230607/wrr/winrar-x64-622sc.exe
#6.22
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230607/rrlb/winrar-x32-622sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230607/rrlb/winrar-x64-622sc.exe
#6.21
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230223/rrlb/winrar-x32-621sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20230223/wrr/winrar-x64-621sc.exe
#6.11
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20220317/rrlb/winrar-x32-611sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20220317/wrr/winrar-x64-611sc.exe
#6.10
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20220127/rrlb/winrar-x32-610sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20220127/wrr/winrar-x64-610sc.exe
#6.02
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20210616/wrr/wrar602sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20210616/wrr/winrar-x64-602sc.exe
#6.00
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20201210/wrr/wrar600sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20201210/rrlb/winrar-x64-600sc.exe
#5.91
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20200827/wrr/wrar591sc.exe
#64位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20200827/rrlb/winrar-x64-591sc.exe
#5.90
#32位：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20200409/rrlb/wrar590sc.exe
#64位： https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20200409/rrlb/winrar-x64-590sc.exe
#5.80
#32：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20191217/wrr/wrar580sc.exe
#64：https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20191217/rrlb/winrar-x64-580sc.exe
#5.71
#32：https://www.win-rar.com/fileadmin/winrar-versions/sc20190509/wrr/wrar571sc.exe
#64：https://www.win-rar.com/fileadmin/winrar-versions/sc20190509/wrr/winrar-x64-571sc.exe
